import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
// 适配像素
import 'package:in_out_goods_manage/utiles/adapation.dart';
// image 背景盒子
import 'package:in_out_goods_manage/components/image_bg_box.dart';
// 判断权限
// import './permission_request.dart';
// import 'package:permission_handler/permission_handler.dart' show Permission;
import 'package:provider/provider.dart' show Consumer;
// 商品信息
import 'package:in_out_goods_manage/model/goods_manage.dart';

class MyHomePage extends HookWidget {
  const MyHomePage({super.key});

  @override
  Widget build(BuildContext context) {
    // 初始化AdaptSize
    AdaptSize.initialize(context);
    return Scaffold(
        appBar: AppBar(
          title: const Text('inventory'),
          centerTitle: true,
        ),
        body: SizedBox(
          width: double.infinity,
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              SizedBox(height: AdaptSize.px(16.5)),
              ImgBgBox(
                assetName: 'assets/images/inventory_bg.png',
                width: AdaptSize.px(345),
                height: AdaptSize.px(148.5),
                child:
                    Consumer<GoodsManageModel>(builder: (_, goodManage, child) {
                  return Column(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        SizedBox(height: AdaptSize.px(22)),
                        Text(
                          'onHandInventory',
                          style: TextStyle(
                            color: const Color(0xFF666666),
                            fontSize: AdaptSize.px(12),
                          ),
                        ),
                        Text(
                          goodManage.goodsCount(),
                          style: TextStyle(
                            fontSize: AdaptSize.px(37),
                          ),
                        ),
                        Row(
                          mainAxisAlignment: MainAxisAlignment.spaceAround,
                          children: [
                            Column(
                              children: [
                                Text(
                                  goodManage.reduce.toString(),
                                  style: TextStyle(
                                    fontSize: AdaptSize.px(14),
                                  ),
                                ),
                                Text(
                                  'yesterdaySDeliveryVice',
                                  style: TextStyle(
                                    color: const Color(0xFF666666),
                                    fontSize: AdaptSize.px(11),
                                  ),
                                ),
                              ],
                            ),
                            Column(
                              children: [
                                Text(
                                  goodManage.addNum.toString(),
                                  style: TextStyle(
                                    fontSize: AdaptSize.px(14),
                                  ),
                                ),
                                Text(
                                  'yesterdaySWarehousingVice',
                                  style: TextStyle(
                                    color: const Color(0xFF666666),
                                    fontSize: AdaptSize.px(11),
                                  ),
                                ),
                              ],
                            )
                          ],
                        )
                      ]);
                }),
              ),
              SizedBox(height: AdaptSize.px(20.5)),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                children: [
                  FooterBtn(
                    assetName: 'assets/images/scan.png',
                    title: 'sweepIt',
                    onPressed: () =>
                        {Navigator.pushNamed(context, '/scanPage')},
                  ),
                  FooterBtn(
                    assetName: 'assets/images/goodsManage.png',
                    title: 'merchandiseManagement',
                    onPressed: () =>
                        {Navigator.pushNamed(context, '/goodsManagePage')},
                  ),
                  FooterBtn(
                    assetName: 'assets/images/statistics.png',
                    title: 'statistics',
                    onPressed: () =>
                        {Navigator.pushNamed(context, '/statisticPage')},
                  ),
                ],
              )
            ],
          ),
        ));
  }
}

class FooterBtn extends HookWidget {
  const FooterBtn(
      {super.key,
      required this.title,
      required this.assetName,
      this.onPressed});
  final String title;
  final String assetName;
  final void Function()? onPressed;
  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        IconButton(
          onPressed: onPressed,
          icon: Image.asset(
            assetName,
            width: AdaptSize.px(56.52),
            height: AdaptSize.px(56.52),
          ),
        ),
        Text(
          title,
          style: TextStyle(fontSize: AdaptSize.px(9.75)),
        )
      ],
    );
  }
}
